package GameTools;

import java.util.StringTokenizer;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;


public class ydPoint {

	public float x;
	public float y;
	
	Paint p = new Paint();

	public ydPoint() {
		x = 0;
		y = 0;
	}

	public ydPoint(float x, float y) {
		this.x = x;
		this.y = y;
	}

	public ydPoint(ydPoint p) {
		this.x = p.x;
		this.y = p.y;
	}



	public void rotate(ydPoint pivot, float rads) {

		double cosVal = Math.cos(rads);
		double sinVal = Math.sin(rads);

		ydPoint tmp = new ydPoint(x, y);

		tmp.x -= pivot.x;
		tmp.y -= pivot.y;

		x = (float) (tmp.x * cosVal - tmp.y * sinVal) + pivot.x;
		y = (float) (tmp.x * sinVal + tmp.y * cosVal) + pivot.y;

		return;

	}
	

	public String toString() {
		return x + " " + y;
	}

	public void degreesToVector(float slopeDegrees) {

		float extra = 0;

		if (slopeDegrees >= 270)
			extra = 270;
		else if (slopeDegrees >= 180)
			extra = 180;
		else if (slopeDegrees >= 90)
			extra = 90;
		else
			extra = 0;

		slopeDegrees -= extra;

		x = (float) Math.cos(Globals.degreesToRads(slopeDegrees));
		y = (float) Math.sin(Globals.degreesToRads(slopeDegrees));

		if ((int) extra == 270) {
			y*=1;
			float tmp =x;
			x=y;
			y=-tmp;
		} else if ((int) extra == 180) {
			x*=-1;
			y*=-1;
		} else if ((int) extra == 90) {
			x*=1;
			y*=-1;
			float tmp =x;
			x=y;
			y=tmp;
		}
		else {
			y*=1;
		}
		
		y*=-1;
	}
	
	public void drawPoint(Canvas canvas){
		p.setColor(Color.GREEN);
		canvas.drawPoint((int)x, (int)y, p);
	}

	public void normailize() {
		float h=(float) Math.hypot(x, y);
		
		x/=h;
		y/=h;
	}
	
	public void deltaMove(ydPoint shift){
		x+=shift.x;
		y+=shift.y;
		
	}

	public static ydPoint stringPairToydPoint(String optString) {
		StringTokenizer st = new StringTokenizer(optString," "); 
		return new ydPoint(Float.parseFloat(st.nextToken()), Float.parseFloat(st.nextToken()));
		
	}

	public void setCoordinates(ydPoint stringPairToydPoint) {
		x=stringPairToydPoint.x;
		y=stringPairToydPoint.y;
		
	}

}
